package com.power.using.myapplication.okhttp;

import com.google.gson.internal.$Gson$Types;

import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import okhttp3.Request;

/**
 * Created by 聪明一只哈 on 2019/9/20.
 * Time: 2019/9/20  17:00
 */
public abstract class CustomCallBack<T>{


    private final Type type;

    public CustomCallBack() {

        /**
         * // 获取当前new的对象的泛型的父类类型
         *         ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
         *         // 获取第一个类型参数的真实类型
         *         this.clazz = (Class<T>) pt.getActualTypeArguments()[0];
         *
         */

        ParameterizedType parameterizedType= (ParameterizedType) this.getClass().getGenericSuperclass();
        //返回集合类型时使用
        type = $Gson$Types.canonicalize(parameterizedType.getActualTypeArguments()[0]);
    }

    public abstract void onBefore(Request request);

    public abstract void requestSuccess(T result);

    public abstract void requestFailure(Request request, IOException exception);

    public abstract  void onAfter();

}
